import React, { Component } from 'react';
import { connect } from 'dva';
import { Card, Form } from 'antd';
import { getNotifyList } from 'Services/publicServer.js';
// import { get } from 'lodash';

const STORE_NAME = 'publicServerNotice';
// const FormItem = Form.Item;

@connect(state => ({
  [STORE_NAME]: state[STORE_NAME],
  loading: state.loading.effects[`${STORE_NAME}/fetchTableDataSource`],
}))
@Form.create()
class publicServerNotice extends Component {
  constructor(props) {
    super(props);
    window.scope = this;
  }

  state = {
    data: [],
  };

  componentDidMount() {
    this.fetchData();
  }

  getDataFromStore = key => (key ? this.props[STORE_NAME][key] : this.props[STORE_NAME]);

  fetchData = () => {
    getNotifyList({ id: '1' }).then(res => {
      this.setState({ data: res.data });
    });
  };

  render() {
    const { data } = this.state;
    return (
      <div>
        <Card title="最新消息">
          {data.map(({ id, title, issueTime }) => {
            return (
              <div
                key={id}
                onClick={() => {
                  this.props.history.push(`/notify/notifyDetail/?id=${id}`);
                }}
              >
                <div
                  style={{
                    width: '80%',
                    display: 'flex',
                    backgroundColor: '#dedede',
                    padding: '10px 15px',
                    justifyContent: 'space-between',
                  }}
                >
                  <div>{title}</div>
                  <div>{issueTime}</div>
                </div>
                <div
                  style={{
                    width: '80%',
                    padding: '10px 15px',
                    backgroundColor: '#eee',
                  }}
                >
                  时间
                </div>
              </div>
            );
          })}
        </Card>
      </div>
    );
  }
}

export default publicServerNotice;
